import asyncio
import sqlalchemy as sa

from aiomysql.sa import create_engine


metadata = sa.MetaData()

platform = sa.Table('accounts_platform', metadata,
               sa.Column('id', sa.Integer, primary_key=True),
               sa.Column('platform', sa.String(50), primary_key=True))

platform_server = sa.Table('accounts_platformserver', metadata,
               sa.Column('id', sa.Integer, primary_key=True),
               sa.Column('broker', sa.String(255)),
               sa.Column('company_name', sa.String(255)),
               sa.Column('platform_server', sa.String(255)),
               sa.Column('platform_id', sa.Integer, sa.ForeignKey('accounts_platform.id')))



async def go(loop):
    engine = await create_engine(user='root', db='klipc_db',
                                 host='47.103.89.53', password='Klipc@2019USA2China', loop=loop)
    async with engine.acquire() as conn:
        await conn.execute(platform)
        await conn.execute(platform.insert().values(val='abc'))
        # await conn.execute(platform.insert().values(val='xyz'))

        async for row in conn.execute(platform.select()):
            print(row.id, row.val)

    engine.close()
    await engine.wait_closed()


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(go(loop))
